package jm.nj.demo22mian.demo;

import org.junit.Test;

import java.sql.*;

public class JdbcDemo {
    /*
    * 使用JDBC入门案例
    *  * @throws ClassNotFoundException
     * @throws SQLException
     * */
    @Test
    public void demo() throws SQLException, ClassNotFoundException {
        //1.注册驱动
        Class.forName ("com.mysql.jdbc.Driver");
        //2.连接数据库
        Connection conn = DriverManager.getConnection("jdbc:mysql:///day22","root","123456");
        //3.创建sql执行平台
        Statement stmt = conn.createStatement();
        //4.执行sql
        ResultSet rs = stmt.executeQuery("select *  from user");
        //5.处理结果
        while(rs.next()){
            Integer uid = rs.getInt("uid");
            String username = rs.getString("username");
            String password = rs.getString("password");
            Double salary = rs.getDouble("salary");
            Integer age = rs.getInt("age");
            Date registTime = rs.getDate("registTime");
            Timestamp lastupdate = rs.getTimestamp("lastupdate");
            System.out.println(uid + "  " + username + "  " + password + "  " + salary + "  " +age + "  " + registTime + "  " + lastupdate);
        }
        //6.释放资源
        rs.close();
        stmt.close();
        conn.close();
    }
}
